<?php
$this->context->bodyClass="index";

use yii\helpers\Html;
use services\models\UpFileData;
use common\models\GoodsRedis;
use services\models\Goods;

$now = date('Y-m-d H:i:s');
?>

<?php  $this->beginBlock('css'); ?>
<link rel="stylesheet" type="text/css" href="<?=Yii::getAlias('@static')?>/wap/liketry/css/index.css">
<?php $this->endBlock();?>

<section>
	<div class="swiper-container">
	    <div class="swiper-wrapper box-flex">
	    	<!--顶部幻灯片图片循环 start-->
	        <?php 
                    if(!empty($banner_list))
                    {
                        foreach($banner_list as $v)
                        {
                ?>
                <div class="swiper-slide flexSh"><a href="<?php echo $v['link']; ?>"><img src="<?= Yii::$app->params['goods_image_url'].$v['img']; ?>"></a></div>
                <?php 
                        }
                    }
                ?>
	        <!--END-->
	    </div>
	    <!-- 如果需要分页器 -->
	    <div class="swiper-pagination"></div>
	</div>
	<div class="index-day">
		<h2>每日一试</h2>
		<?php if(!empty($day_try_list)){
                        foreach($day_try_list as $v){
                        if($now < $v['recommend_time'])  continue;    
                        //$product_info = GoodsRedis::getSkuRedis($v['product_id']);
                ?>
                <a href="<?=Yii::$app->urlManager->createUrl(["goods-detail/index",'product_id'=>$v['product_id']]);?>"><?= Html::img(UpFileData::showImage($v['pic'])); ?></a>
                <?php if($now >= $v['recommend_time'])  break;  
                } }?>
	</div>
	<div class="index-chao">
		<h2>超值试用</h2>
		<ul>
			<!--超值试用 循环最多显示3个 Start-->
            <?php if(isset($super_try_list[1]) && !empty($super_try_list[1])){ 
                    foreach($super_try_list[1] as $v){
                        if($now < $v['recommend_time'])  continue;
                        $product_info = GoodsRedis::getSkuRedis($v['product_id']);
                        $goods_info = Goods::findByGoodsIdFromRedis($v['goods_id']);
            ?>   
			<li>
                <a href="<?=Yii::$app->urlManager->createUrl(["goods-detail/index",'product_id'=>$v['product_id']]);?>">
                <div class="top">
                    <img data-original="<?php echo \Yii::$app->params['goods_image_url'] . str_replace('./upload/', 'upload/', $goods_info['pic']);?>" />
                    <div class="try-bg"></div>
                </div>
                <div class="title"><?php echo $goods_info['goods_name']; ?></div>
    			<div class="price">
                    <?php if($product_info['type'] == 1)
                    {
                    ?>
                    <p class="p-try"><i></i><?php echo $product_info['try_price']; ?></p><!--试豆价格-->
                    <?php
                    } elseif($product_info['type'] == 2)
                    {
                    ?>
                    <p class="p-sell"><i></i><?php echo $product_info['sale_price']; ?></p><!--价格-->
                    <?php
                    }else
                    {
                    ?>
                    <p class="p-sell"><i></i><?php echo $product_info['sale_price']; ?></p><!--价格-->
                    <p class="p-try"><i></i><?php echo $product_info['try_price']; ?></p><!--试豆价格-->
                    <?php
                    }
                    ?>
                </div>
                </a>
            </li>
            <?php if($now >= $v['recommend_time'])  break;       
                    } }?> 
            <?php if(isset($super_try_list[2]) && !empty($super_try_list[2])){ 
                    foreach($super_try_list[2] as $v){
                        if($now < $v['recommend_time'])  continue;
                        $product_info = GoodsRedis::getSkuRedis($v['product_id']);
                        $goods_info = Goods::findByGoodsIdFromRedis($v['goods_id']);
            ?>   
			<li>
            <a href="<?=Yii::$app->urlManager->createUrl(["goods-detail/index",'product_id'=>$v['product_id']]);?>">
                <div class="top">
    				<img data-original="<?php echo \Yii::$app->params['goods_image_url'] . str_replace('./upload/', 'upload/', $goods_info['pic']);?>" />
    				<div class="try-bg"></div>
                </div>
                <div class="title"><?php echo $goods_info['goods_name']; ?></div>
    			<div class="price">
                <?php if($product_info['type'] == 1)
                {
                ?>
                <p class="p-try"><i></i><?php echo $product_info['try_price']; ?></p><!--试豆价格-->
                <?php
                } elseif($product_info['type'] == 2)
                {
                ?>
                <p class="p-sell"><i></i><?php echo $product_info['sale_price']; ?></p><!--价格-->
                <?php
                }else
                {
                ?>
					<p class="p-sell"><i></i><?php echo $product_info['sale_price']; ?></p><!--价格-->
					<p class="p-try"><i></i><?php echo $product_info['try_price']; ?></p><!--试豆价格-->
                                            <?php
                                            }
                                            ?>
                </div>
            </a>
            </li>
            <?php if($now >= $v['recommend_time'])  break;       
                    } }?> 
            <?php if(isset($super_try_list[3]) && !empty($super_try_list[3])){ 
                    foreach($super_try_list[3] as $v){
                        if($now < $v['recommend_time'])  continue;
                        $product_info = GoodsRedis::getSkuRedis($v['product_id']);
                        $goods_info = Goods::findByGoodsIdFromRedis($v['goods_id']);
            ?>   
			<li>
            <a href="<?=Yii::$app->urlManager->createUrl(["goods-detail/index",'product_id'=>$v['product_id']]);?>">
				<div class="top">
                    <img data-original="<?php echo \Yii::$app->params['goods_image_url'] . str_replace('./upload/', 'upload/', $goods_info['pic']);?>" />
				   <div class="try-bg"></div>
                </div>
                <div class="title"><?php echo $goods_info['goods_name']; ?></div>
                <div class="price">
                    <?php if($product_info['type'] == 1)
                    {
                    ?>
                    <p class="p-try"><i></i><?php echo $product_info['try_price']; ?></p><!--试豆价格-->
                    <?php
                    } elseif($product_info['type'] == 2)
                    {
                    ?>
                    <p class="p-sell"><i></i><?php echo $product_info['sale_price']; ?></p><!--价格-->
                    <?php
                    }else
                    {
                    ?>
					<p class="p-sell"><i></i><?php echo $product_info['sale_price']; ?></p><!--价格-->
					<p class="p-try"><i></i><?php echo $product_info['try_price']; ?></p><!--试豆价格-->
                                        <?php
                                        }
                                        ?>
				</div>
            </a>
            </li>
            <?php if($now >= $v['recommend_time'])  break;       
            } }?> 
			
			<!--超值试用 循环最多显示3个 End-->
		</ul>
	</div>
    <?php if(isset($try_rec_list) && !empty($try_rec_list)){?>
	<div class="index-little">
		<h2>小试推荐</h2>
		<ul class="clear">
			<!--小试推荐 循环 Start-->
                        <?php foreach($try_rec_list as $line_id => $val){
                        foreach ($val as $v){
                            if($now < $v['recommend_time'])  continue;  
                            $pic_array = explode(',', $v['pic']); 
                            $product_info1 = GoodsRedis::getSkuRedis($v['product_id1']);
                            $goods_info1 = Goods::findByGoodsIdFromRedis($v['goods_id1']);
                            $product_info2 = GoodsRedis::getSkuRedis($v['product_id2']);
                            $goods_info2 = Goods::findByGoodsIdFromRedis($v['goods_id2']);
                            $product_info3 = GoodsRedis::getSkuRedis($v['product_id3']);
                            $goods_info3 = Goods::findByGoodsIdFromRedis($v['goods_id3']);
                        ?>
			<li class="box-sizing"><a href="<?=Yii::$app->urlManager->createUrl(["goods-detail/index",'product_id'=>$v['product_id1']]);?>">
				<div class="top"><img data-original="<?php echo \Yii::$app->params['goods_image_url'] . str_replace('./upload/', 'upload/', $goods_info1['pic']);?>" />
                </div>
				<div class="title"><?php echo $goods_info1['goods_name']; ?></div>
				<div class="price">
					<?php if($product_info1['type'] == 1)
                                        {
                                        ?>
                                        <p class="p-try"><i></i><?php echo $product_info1['try_price']; ?></p><!--试豆价格-->
                                        <?php
                                        } elseif($product_info1['type'] == 2)
                                        {
                                        ?>
                                        <p class="p-sell"><i></i><?php echo $product_info1['sale_price']; ?></p><!--价格-->
                                        <?php
                                        }else
                                        {
                                        ?>
                                            <p class="p-sell"><i></i><?php echo $product_info1['sale_price']; ?></p><!--价格-->
                                            <p class="p-try"><i></i><?php echo $product_info1['try_price']; ?></p><!--试豆价格-->
                                        <?php
                                        }
                                        ?>
				</div>
			</a></li>
			<li class="box-sizing"><a href="<?=Yii::$app->urlManager->createUrl(["goods-detail/index",'product_id'=>$v['product_id2']]);?>">
				<div class="top"><img data-original="<?php echo \Yii::$app->params['goods_image_url'] . str_replace('./upload/', 'upload/', $goods_info2['pic']);?>" /></div>
				<div class="title"><?php echo $goods_info2['goods_name']; ?></div>
				<div class="price">
					<?php if($product_info2['type'] == 1)
                                        {
                                        ?>
                                        <p class="p-try"><i></i><?php echo $product_info2['try_price']; ?></p><!--试豆价格-->
                                        <?php
                                        } elseif($product_info2['type'] == 2)
                                        {
                                        ?>
                                        <p class="p-sell"><i></i><?php echo $product_info2['sale_price']; ?></p><!--价格-->
                                        <?php
                                        }else
                                        {
                                        ?>
                                            <p class="p-sell"><i></i><?php echo $product_info2['sale_price']; ?></p><!--价格-->
                                            <p class="p-try"><i></i><?php echo $product_info2['try_price']; ?></p><!--试豆价格-->
                                        <?php
                                        }
                                        ?>
				</div>
			</a></li>
			<li class="box-sizing"><a href="<?=Yii::$app->urlManager->createUrl(["goods-detail/index",'product_id'=>$v['product_id3']]);?>">
				<div class="top"><img data-original="<?php echo \Yii::$app->params['goods_image_url'] . str_replace('./upload/', 'upload/', $goods_info3['pic']);?>" /></div>
				<div class="title"><?php echo $goods_info3['goods_name']; ?></div>
				<div class="price">
					<?php if($product_info3['type'] == 1)
                                        {
                                        ?>
                                        <p class="p-try"><i></i><?php echo $product_info3['try_price']; ?></p><!--试豆价格-->
                                        <?php
                                        } elseif($product_info3['type'] == 2)
                                        {
                                        ?>
                                        <p class="p-sell"><i></i><?php echo $product_info3['sale_price']; ?></p><!--价格-->
                                        <?php
                                        }else
                                        {
                                        ?>
                                            <p class="p-sell"><i></i><?php echo $product_info3['sale_price']; ?></p><!--价格-->
                                            <p class="p-try"><i></i><?php echo $product_info3['try_price']; ?></p><!--试豆价格-->
                                        <?php
                                        }
                                        ?>
				</div>
			</a></li>
			<?php if($now >= $v['recommend_time'])  break;  
                        }} ?>
			<!--小试推荐 循环 End-->
		</ul>
	</div>
    <?php } ?>
</section>

<nav>
    <div class="box">
    <a href="<?=Yii::$app->urlManager->createUrl(['index/index']);?>" class="flex1 cur"><span></span><p>首页</p></a>
    <a href="<?=Yii::$app->urlManager->createUrl(['category/index']);?>" class="flex1"><span></span><p>分类</p></a>
    <a href="<?=Yii::$app->urlManager->createUrl(['cart/index']);?>" class="flex1"><span></span><p>购物车</p></a>
    <a href="<?=Yii::$app->urlManager->createUrl(['user-center/index']);?>" class="flex1"><span></span><p>个人中心</p></a>
    </div>
</nav>

<?php $this->beginBlock('js');?>
<script src="<?=Yii::getAlias('@static')?>/wap/common/js/zepto.min.js"></script>
<script src="<?=Yii::getAlias('@static')?>/wap/common/js/fastclick.min.js"></script>
<script src="<?=Yii::getAlias('@static')?>/wap/common/js/lazyload.js"></script>
<script src="<?=Yii::getAlias('@static')?>/wap/common/js/swiper-3.3.1.jquery.min.js"></script>
<script>
$(function(){
	$(".index-day img, .index-chao img, .index-little img").lazyload({ 
		placeholder: "",
		threshold: 100
	});
	window.onload=function(){setTimeout(function(){$(window).trigger("scroll")},0)}//修复ios下延迟加载时刷新页面图片不加载bug
    var mySwiper = new Swiper('.swiper-container',{
        loop : true,
        autoplay: 3000,
        pagination: '.swiper-pagination'
    });
	
})
</script>
<?php $this->endBlock();?>
